﻿using System;

namespace NetMicro.ExcelMapper
{
    /// <summary>
    /// 格式化扩展
    /// </summary>
    public static class FormatExtensions
    {
        /// <summary>
        /// 使用自定义格式
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="propertyType">要格式化的属性的类型</param>
        /// <param name="customFormat">定类型的自定义格式.</param>
        public static ExcelMapper UseFormat(this ExcelMapper mapper, Type propertyType, string customFormat)
        {
            if (mapper == null) throw new ArgumentNullException(nameof(mapper));
            if (propertyType == null) throw new ArgumentNullException(nameof(propertyType));
            if (string.IsNullOrWhiteSpace(customFormat)) throw new ArgumentException($"Parameter '{nameof(customFormat)}' cannot be null or white space.");

            mapper.TypeFormats[propertyType] = customFormat;

            return mapper;
        }
    }
}
